package com.example.activitidemo.service.event;


import com.example.activitidemo.dao.AssigneeRepository;
import com.example.activitidemo.dto.User1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

import static com.example.activitidemo.dto.Constants.DISABLED;
import static com.example.activitidemo.dto.Constants.USABLE;

/**
 * @author 张志鹏
 */
@Transactional(rollbackFor = Exception.class)
@Service
public class AssigneeService {
    @Autowired
    private AssigneeRepository assigneeRepository;

    public List<User1> findAll() {
        return assigneeRepository.findAllByState(USABLE);
    }

    public void save(User1 user1) {
        user1.date(new Date()).state(USABLE);
        assigneeRepository.save(user1);
    }

    public void delete(String id) {
        User1 user1 = assigneeRepository.getOne(id);
        user1.state(DISABLED);
        assigneeRepository.save(user1);
    }
}
